mod walker;

use ggez::{Context, GameResult, GameError, graphics};
use ggez::mint::Point2;

pub struct State{
    walker: walker::Walker,
}

impl State{
    pub fn new() -> State {
        State{walker : walker::Walker::new(Point2 { x: 200.0, y: 300.0 })}
    }
}

impl ggez::event::EventHandler<GameError> for State {
    fn update(&mut self, ctx: &mut Context) -> GameResult {
        let target = ctx.mouse.position();
        let new_location = Point2 {x: target.x as f64, y: target.y as f64};
        self.walker.move_to(new_location);

        Ok(())
    }
    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::WHITE);
        let location: Point2<f32> = Point2 {x: self.walker.get_location().x as f32, y: self.walker.get_location().y as f32};
        let circle = graphics::Mesh::new_circle(
            ctx,
            graphics::DrawMode::fill(),
            location,
            16.0,
            0.1,
            graphics::Color::BLACK,
        )?;
        canvas.draw(&circle, graphics::DrawParam::default());
        
        canvas.finish(ctx)?;
        Ok(())
    }
}